package edu.isistan.metamodel;

import java.util.Vector;
/**
 * Represents an operation which belongs to an interface
 */
public class Operation extends ModelElement {
	
	private Vector<DataType> returnValue;
	private Vector<DataType> parameters;
	private Vector<String> paranames;
	private String doc;
	
	public Vector<String> getParanames() {
		return paranames;
	}

	public void setParanames(Vector<String> paranames) {
		this.paranames = paranames;
	}

	public String getParaname(int num) {
		return paranames.get(num);
	}
	
	public Operation(String name, Vector<DataType> returnValue,
			Vector<DataType> parameters, Vector<String> paranames, String doc) {
		super();
		this.name = name;
		this.returnValue = returnValue;
		this.parameters = parameters;
		this.paranames = paranames;
		this.doc = doc;
	}
	
	public Operation(String name, DataType returnValue,
			Vector<DataType> parameters, Vector<String> paranames, String doc) {
		super();
		this.name = name;
		this.returnValue = new Vector<DataType>();
		this.returnValue.add(returnValue);		
		this.parameters = parameters;
		this.paranames = paranames;
		this.doc = doc;
	}
	
	public Operation() {
		this.name = null;
		this.returnValue = null;
		this.parameters = null;
		this.doc = null;
	}

	public Operation(Operation operation) {
		super();
		this.name = operation.getName();
		this.returnValue = new Vector<DataType>();
		for (DataType dataType : operation.getReturnValue()) {
			this.returnValue.add(dataType.copy());
		}
		this.parameters = new Vector<DataType>();
		for (DataType dataType : operation.getParameters()) {
			this.parameters.add(dataType.copy());
		}
		this.paranames = operation.getParanames();
		this.doc = operation.getDoc();
	}
	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	public String getDoc() {
		return doc;
	}

	public void setDoc(String doc) {
		this.doc = doc;
	}

	public Vector<DataType> getReturnValue() {
		return returnValue;
	}

	public void setReturnValue(Vector<DataType> returnValue) {
		this.returnValue = returnValue;
	}

	public Vector<DataType> getParameters() {
		return parameters;
	}

	public void setParameters(Vector<DataType> parameters) {
		this.parameters = parameters;
	}
	
	public int getParametersSize() {
		if(parameters != null)
			return parameters.size();
		else 
			return 0;
	}
	
	public DataType getParameter(int num) {
		return parameters.get(num);
	}
		
	public void addParameter(DataType dataType, String name) {
		if(parameters == null)
			parameters = new Vector<DataType>();
		parameters.add(dataType);
		if(paranames == null)
			paranames = new Vector<String>();
		paranames.add(name);
	}
	public int getReturnSize() {
		if(returnValue != null)
			return returnValue.size();
		else 
			return 0;
	}
	
	public void addReturnParameter(DataType dataType) {
		if(returnValue == null)
			returnValue = new Vector<DataType>();
		returnValue.add(dataType);
	}	
	
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("{name=");
		sb.append(getName());
		sb.append(";input=[");
		int i = 0;
		for (DataType in : getParameters()) {			
			sb.append(in.toString());
			sb.append(" " + getParaname(i));
			i++;
		}
		sb.append("];output=[");
		for (DataType out : getReturnValue()) {
			sb.append(out.toString());
		}
		sb.append("]}");
		return sb.toString();
	}

	
}
